// @Author EthanScriptOn
// @Desc
package log

import (
	"errors"
	"gitee.com/fatzeng/srf_switch_log/log_define"
	"gitee.com/fatzeng/srf_switch_protocol/protocol/log"
)

func Logger() (log.Log, error) {
	instanceInter, err := logInitialization.Get()
	if err != nil {
		return nil, err
	}
	if instance, ok := instanceInter.(log.Log); !ok {
		return instance, nil
	}
	return nil, errors.New("logInitialization instance must implement Log interface")
}

func GenerateSrfSwitchLog(logCenter *LogCenter) *SrfSwitchLog {
	return &SrfSwitchLog{logCenter: logCenter}
}

type SrfSwitchLog struct {
	logCenter *LogCenter
}

func (s *SrfSwitchLog) All(key interface{}, value ...interface{}) {
	s.putReserve(&LogSnapshot{Key: key, Value: value, CallDepth: 1, Level: log_define.ALL})
}
func (s *SrfSwitchLog) Trace(key interface{}, value ...interface{}) {
	s.putReserve(&LogSnapshot{Key: key, Value: value, CallDepth: 1, Level: log_define.TRACE})
}
func (s *SrfSwitchLog) Debug(key interface{}, value ...interface{}) {
	s.putReserve(&LogSnapshot{Key: key, Value: value, CallDepth: 1, Level: log_define.DEBUG})
}
func (s *SrfSwitchLog) Info(key interface{}, value ...interface{}) {
	s.putReserve(&LogSnapshot{Key: key, Value: value, CallDepth: 1, Level: log_define.INFO})
}
func (s *SrfSwitchLog) Warn(key interface{}, value ...interface{}) {
	s.putReserve(&LogSnapshot{Key: key, Value: value, CallDepth: 1, Level: log_define.WARN})
}
func (s *SrfSwitchLog) Error(key interface{}, value ...interface{}) {
	s.putReserve(&LogSnapshot{Key: key, Value: value, CallDepth: 1, Level: log_define.ERROR})
}
func (s *SrfSwitchLog) Fatal(key interface{}, value ...interface{}) {
	s.putReserve(&LogSnapshot{Key: key, Value: value, CallDepth: 1, Level: log_define.FATAL})
}

func (s *SrfSwitchLog) putReserve(logSnapshot *LogSnapshot) {
	_ = s.logCenter.Record(logSnapshot)
}
